/******/ (() => { // webpackBootstrap
/******/ 	"use strict";
/******/ 	var __webpack_modules__ = ({

/***/ "./Setting.ts":
/*!********************!*\
  !*** ./Setting.ts ***!
  \********************/
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {


Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.Setting = void 0;
var FairyEditor = CS.FairyEditor;
const Util_1 = __webpack_require__(/*! ./Util */ "./Util.ts");
const fs = CS.System.IO.File;
const director = CS.System.IO.Directory;
const Path = CS.System.IO.Path;
class Setting {
    assetsPath;
    uiJsonPath;
    uiPath;
    constructor() {
        const App = FairyEditor.App;
        let s = this;
        let publishPath;
        publishPath = Path.Combine(App.project.settingsPath, "GYPublish.json");
        s.assetsPath = Util_1.Util.getParentDirectory(App.project.basePath);
        s.uiJsonPath = Path.Combine(s.assetsPath, "uiJson"),
            s.uiPath = Path.GetFullPath("src/UI/layout", Util_1.Util.getParentDirectory(s.assetsPath, 2));
        if (!fs.Exists(publishPath)) {
            let defaultSetting = {
                assetPath: s.assetsPath,
                uiJsonPath: s.uiJsonPath,
                uiBase: s.uiPath
            };
            console.log("不存在羔羊发布配置，自动创建!" + publishPath);
            fs.WriteAllText(publishPath, JSON.stringify(defaultSetting, null, 4));
        }
        else
            console.log("存在羔羊发布配置!" + publishPath);
        //ui布局目录
        if (!director.Exists(s.uiJsonPath))
            director.CreateDirectory(s.uiJsonPath);
        if (!director.Exists(s.uiJsonPath))
            console.error("插件无法使用，uiJson目录不存在！" + s.uiJsonPath);
        //ui布局代码目录
        if (!director.Exists(s.uiPath))
            director.CreateDirectory(s.uiPath);
        if (!director.Exists(s.uiPath))
            console.error("插件无法使用，资源目录不存在！" + s.uiPath);
    }
}
exports.Setting = Setting;


/***/ }),

/***/ "./Util.ts":
/*!*****************!*\
  !*** ./Util.ts ***!
  \*****************/
/***/ ((__unused_webpack_module, exports) => {


Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.Util = void 0;
const Path = CS.System.IO.Path;
class Util {
    static getParentDirectory(path, levels = 1) {
        for (let i = 0; i < levels; i++) {
            path = Path.GetDirectoryName(path);
            if (path == null || path == "")
                break;
        }
        return path;
    }
}
exports.Util = Util;


/***/ }),

/***/ "./xmlUIParse/DOMParser.ts":
/*!*********************************!*\
  !*** ./xmlUIParse/DOMParser.ts ***!
  \*********************************/
/***/ ((__unused_webpack_module, exports) => {


Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.DOMParser = void 0;
class DOMParser {
    index = 0;
    xml;
    constructor() {
    }
    parseFromString(xml) {
        this.xml = `<document>` + xml.replace(/<\?xml.*?\?>\s*/s, '')
            .replace(/\n\s+/g, ' ') // 标准化空白字符
            .trim() + `</document>`;
        return this.parseNode();
    }
    parseNode() {
        this.consume('<');
        const tagName = this.parseTagName();
        const attributes = this.parseAttributes();
        const node = { nodeName: tagName, children: [], attributes: [] };
        if (attributes.length > 0) {
            node.attributes = attributes;
        }
        // 处理自闭合标签
        if (this.peek() === '/') {
            this.consume('/');
            this.consume('>');
            return node;
        }
        this.consume('>');
        node.children = this.parseChildren(tagName);
        return node;
    }
    parseTagName() {
        let tagName = '';
        while (/[^\s/>]/.test(this.peek())) {
            tagName += this.xml[this.index++];
        }
        return tagName;
    }
    parseAttributes() {
        const attributes = [];
        while (this.peek() !== '>' && this.peek() !== '/') {
            this.consumeWhitespace();
            const localName = this.parseAttributeKey();
            this.consume('=');
            const value = this.parseAttributeValue();
            attributes[attributes.length] = { localName: localName, value: value };
        }
        return attributes;
    }
    parseAttributeKey() {
        let key = '';
        while (/[^\s=]/.test(this.peek())) {
            key += this.xml[this.index++];
        }
        return key;
    }
    parseAttributeValue() {
        const quote = this.consume();
        let value = '';
        while (this.peek() !== quote) {
            value += this.xml[this.index++];
        }
        this.consume(quote);
        return value;
    }
    parseChildren(parentTag) {
        const children = [];
        while (true) {
            this.consumeWhitespace();
            // 增强结束标签检测
            if (this.checkClosingTag(parentTag)) {
                break;
            }
            if (this.peek() === '<') {
                children.push(this.parseNode());
            }
            else {
                // 跳过文本内容（可选保留逻辑）
                this.index++;
            }
        }
        return children;
    }
    checkClosingTag(parentTag) {
        if (this.peek() === '<' && this.xml[this.index + 1] === '/') {
            const closingIndex = this.index;
            this.consume('<');
            this.consume('/');
            this.consumeWhitespace();
            const endTag = this.parseTagName();
            this.consumeWhitespace();
            this.consume('>');
            if (endTag !== parentTag) {
                throw new Error(`标签不匹配: 期待 ${parentTag} 实际 ${endTag}`);
            }
            return true;
        }
        return false;
    }
    consume(char) {
        if (char && this.xml[this.index] !== char) {
            throw new Error(`在位置 ${this.index} 期待 "${char}" 但发现 "${this.xml[this.index]}"`);
        }
        return this.xml[this.index++];
    }
    consumeWhitespace() {
        while (/\s/.test(this.peek())) {
            this.index++;
        }
    }
    peek() {
        return this.xml[this.index] || '';
    }
}
exports.DOMParser = DOMParser;
// let obj=(new DOMParser).parseFromString(`<?xml version="1.0" encoding="utf-8"?>
// <component size="161,161" extention="Button">
//   <Button/>
//   <controller name="button" pages="0,up,1,down,2,over,3,selectedOver"/>
//   <displayList>
//     <image id="n0_gl7v" src="hcice" name="n0" xy="0,0">
//       <relation target="" sidePair="width,height"/>
//     </image>
//   </displayList>
// </component>`);
// App.Alert(JSON.stringify(obj));


/***/ }),

/***/ "./xmlUIParse/PropType.ts":
/*!********************************!*\
  !*** ./xmlUIParse/PropType.ts ***!
  \********************************/
/***/ ((__unused_webpack_module, exports) => {


Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.PropType = void 0;
class PropType {
    static NUMBER = new PropType(0, "数字", "number");
    static STRING = new PropType(1, "字符串", "string");
    static ARRAY = new PropType(2, "数组", "any[]");
    static OBJECT = new PropType(3, "对象", "any");
    static ARRAY2 = new PropType(4, "二维数组", "any[][]");
    static INT = new PropType(5, "整型", "int");
    static UINT = new PropType(6, "无符号整型", "uint");
    static BOOL = new PropType(7, "布尔类型", "boolean");
    static ARRAY_OBJECT = new PropType(8, "对象数组", "any[]");
    static ARRAY_NUMBER = new PropType(9, "数字数组", "number[]");
    static typeList = [PropType.NUMBER, PropType.STRING,
        PropType.ARRAY, PropType.OBJECT, PropType.ARRAY2, PropType.INT, PropType.UINT, PropType.BOOL, PropType.ARRAY_OBJECT, PropType.ARRAY_NUMBER];
    static getType(id) {
        return PropType.typeList[id];
    }
    // public static readonly ARRAY_PAIR:PropType=new PropType(100,"ly.Pair数组");
    _name;
    _id;
    _key;
    constructor(id, name, key) {
        let s = this;
        s._id = id;
        s._name = name;
        s._key = key;
    }
    typeToStr(val) {
        let s = this;
        let str;
        if (s == PropType.NUMBER)
            return val == null ? "0" : String(val);
        if (s == PropType.INT)
            return String(Math.floor(val));
        if (s == PropType.UINT)
            return String(Math.abs(val));
        if (s == PropType.STRING)
            return val == null ? "" : String(val);
        if (s == PropType.ARRAY)
            return val ? val.toString() : "";
        if (s == PropType.BOOL)
            return val && val != "0" ? "true" : "false";
        if (s == PropType.ARRAY2) {
            if (val == null)
                return "";
            str = val.toString();
            return str.substr(1, str.length - 2);
        }
        if (s == PropType.OBJECT || s == PropType.ARRAY_OBJECT) {
            if (val.contructor == String)
                return val;
            return JSON.stringify(val);
        }
        return "";
    }
    strToValue(val) {
        let s = this;
        if (s == PropType.NUMBER)
            return Number(val);
        if (s == PropType.INT)
            return val | 0;
        if (s == PropType.UINT)
            return Math.abs(val | 0);
        if (s == PropType.STRING)
            return val == null ? "" : String(val);
        if (s == PropType.BOOL)
            return val === "true" || val == "1" ? true : false;
        if (s == PropType.ARRAY)
            return val ? val.split(",") : [];
        if (s == PropType.ARRAY_NUMBER) {
            if (val) {
                val = val.split(",");
                let i, len;
                len = val.length;
                for (i = 0; i < len; ++i) {
                    val[i] = Number(val[i]);
                }
                return val;
            }
            else
                return [];
        }
        if (s == PropType.ARRAY2)
            return s.parse("[" + (val ? val : "") + "]");
        if (s == PropType.OBJECT || s == PropType.ARRAY_OBJECT)
            return s.parse(val);
    }
    parse(val) {
        try {
            return JSON.parse(val);
        }
        catch (e) {
            let s = this;
            return s == PropType.ARRAY2 || s == PropType.ARRAY_OBJECT ? [] : null;
        }
    }
    isArray() {
        let s = this;
        return s == PropType.ARRAY2 || s == PropType.ARRAY_OBJECT || s == PropType.ARRAY;
    }
    isNumber() {
        let s = this;
        return s == PropType.UINT || s == PropType.INT || s == PropType.NUMBER;
    }
}
exports.PropType = PropType;


/***/ }),

/***/ "./xmlUIParse/XMLConfig.ts":
/*!*********************************!*\
  !*** ./xmlUIParse/XMLConfig.ts ***!
  \*********************************/
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {


Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.XMLConfig = void 0;
const PropType_1 = __webpack_require__(/*! ./PropType */ "./xmlUIParse/PropType.ts");
class XMLConfig {
    /***属性定义
         * names字段表示属性的别名，注意属性可能是多个字段组合，它的值由分隔符隔开，所以别名是数组
         * type 字段类型
         * enum 字段的值可能是枚举，所以也记录一下枚举值
        */
    static attri = {
        "name": { type: PropType_1.PropType.STRING },
        "xy": { names: ["x", "y"], type: PropType_1.PropType.NUMBER },
        "size": { names: ["width", "height"], type: PropType_1.PropType.NUMBER },
        "scale": { names: ["scaleX", "scaleY"], type: PropType_1.PropType.NUMBER },
        "skew": { names: ["skewX", "skewY"], type: PropType_1.PropType.NUMBER },
        "rotation": { type: PropType_1.PropType.NUMBER },
        "pivot": { names: ["anchorX", "anchorY"], type: PropType_1.PropType.NUMBER },
        "alpha": { type: PropType_1.PropType.NUMBER },
        "visible": { type: PropType_1.PropType.BOOL },
        "touchable": { names: ["touchabled"], type: PropType_1.PropType.BOOL },
        "grayed": { type: PropType_1.PropType.BOOL },
        "fold": { enum: ["both", "hz", "vt"], type: PropType_1.PropType.STRING },
        "overflow": { names: ["scrollPolicy"], enum: ["show", "hidden", "scroll"], type: PropType_1.PropType.STRING },
        "tooltips": { names: ["toolTipString"], type: PropType_1.PropType.STRING },
        "fileName": { type: PropType_1.PropType.STRING },
        "layout": { type: PropType_1.PropType.STRING, enum: ["col", "row", "flow_hz", "flow_vt", "pagination"] },
        "defaultItem": { type: PropType_1.PropType.STRING },
        "type": { type: PropType_1.PropType.STRING, enum: ["rect", "eclipse", "polygon", "regular_polygon"] },
        "lineSize": { type: PropType_1.PropType.NUMBER },
        "lineColor": { type: PropType_1.PropType.STRING },
        "fillColor": { type: PropType_1.PropType.STRING },
        "points": { type: PropType_1.PropType.ARRAY_NUMBER },
        "sides": { type: PropType_1.PropType.NUMBER },
        "sidePair": { type: PropType_1.PropType.ARRAY, enum: ["left-left", "right-right", "top-top", "bottom-bottom", "center-center", "middle-middle", "width-width", "height-height"] },
        "target": { type: PropType_1.PropType.STRING },
        "path": { type: PropType_1.PropType.STRING },
        "id": { type: PropType_1.PropType.STRING },
        "scale9grid": { type: PropType_1.PropType.ARRAY },
        "extention": { type: PropType_1.PropType.STRING },
        "src": { type: PropType_1.PropType.STRING },
        "pkg": { type: PropType_1.PropType.STRING },
        "text": { type: PropType_1.PropType.STRING },
        "font": { type: PropType_1.PropType.STRING },
        "color": { type: PropType_1.PropType.STRING },
        "fontSize": { names: ["size"], type: PropType_1.PropType.NUMBER },
        "align": { type: PropType_1.PropType.STRING },
        "singleLine": { names: ["mutiline"], type: PropType_1.PropType.BOOL },
        "bold": { type: PropType_1.PropType.BOOL },
        "italic": { type: PropType_1.PropType.BOOL },
        "underline": { type: PropType_1.PropType.BOOL },
        "leading": { names: ["mutiline"], type: PropType_1.PropType.NUMBER },
        "letterSpace": { type: PropType_1.PropType.NUMBER },
        "vAlign": { names: ["verticalAlign"], type: PropType_1.PropType.STRING },
        "prompt": { type: PropType_1.PropType.STRING },
        "maxLength": { names: ["maxChars"], type: PropType_1.PropType.NUMBER },
        "restrict": { type: PropType_1.PropType.STRING },
        "password": { names: ["displayAsPassword"], type: PropType_1.PropType.BOOL },
        "input": { type: PropType_1.PropType.BOOL },
        "strokeColor": { type: PropType_1.PropType.STRING },
        "strokeSize": { names: ["stroke"], type: PropType_1.PropType.NUMBER },
        "shadowColor": { type: PropType_1.PropType.STRING },
        "shadowOffset": { names: ["shadowOffsetX", "shadowOffsetY"], type: PropType_1.PropType.NUMBER },
        "title": { type: PropType_1.PropType.STRING },
        "titleColor": { type: PropType_1.PropType.STRING },
        "titleFontSize": { type: PropType_1.PropType.NUMBER },
        "corner": { type: PropType_1.PropType.NUMBER },
        "mode": { type: PropType_1.PropType.STRING, enum: ["button", "Check", "Radio"] },
    };
    /**标签信息
     * cls 标签对应的类名，如果是显示对象，可用于创建显示对象
    */
    static tag = {
        "component": { cls: "GYLite.GYUIComponent" },
        "image": { cls: "GYLite.GYScaleSprite" },
        "text": { cls: "GYLite.GYText" },
        "list": { cls: "GYLite.GYListV" },
        "loader": { cls: "GYLite.GYLoadImage" },
        "graph": { cls: "GYLite.GYSprite" },
        "richText": { cls: "GYLite.GYRichText" },
        "relation": {},
        "transition": {},
        "item": {},
        "displayList": {},
        "controller": {},
        "packageDescription": {},
        "resources": {},
        "Label": {},
        "ComboBox": {},
        "Button": {},
    };
}
exports.XMLConfig = XMLConfig;


/***/ }),

/***/ "./xmlUIParse/XMLParser.ts":
/*!*********************************!*\
  !*** ./xmlUIParse/XMLParser.ts ***!
  \*********************************/
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {


Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.XMLParser = void 0;
const DOMParser_1 = __webpack_require__(/*! ./DOMParser */ "./xmlUIParse/DOMParser.ts");
const XMLConfig_1 = __webpack_require__(/*! ./XMLConfig */ "./xmlUIParse/XMLConfig.ts");
class XMLParser {
    static _intance;
    static getInstance() {
        return this._intance ||= new XMLParser;
    }
    constructor() {
    }
    parse(xmlString, pkgId = null) {
        let s = this;
        if (!xmlString)
            return null;
        let parser = new DOMParser_1.DOMParser;
        let xml = parser.parseFromString(xmlString);
        let node = xml.children[0];
        let uiJSON = s.parseUI(node, pkgId);
        return uiJSON;
    }
    parseUI(node, pkgId = null) {
        let s = this;
        if (!node)
            return null;
        let tagDef = XMLConfig_1.XMLConfig.tag[node.nodeName];
        let attriDef;
        if (!tagDef)
            return null;
        let attris = node.attributes;
        let displayData;
        if (pkgId == null) {
            let len = attris.length;
            while (--len > -1) {
                if (attris[len].localName == "id") {
                    pkgId = attris[len].value;
                    break;
                }
            }
        }
        displayData ||= { tagName: node.nodeName, pkgId: pkgId };
        //获取组件类名        
        displayData.cls = tagDef.cls;
        displayData.attrs = {};
        //获取组件属性
        let i, len, j, len2, k, len3;
        let attrName;
        let value;
        let values;
        let ind;
        len = attris.length;
        for (i = 0; i < len; ++i) {
            attrName = attris[i].localName;
            attriDef = XMLConfig_1.XMLConfig.attri[attrName];
            if (!attriDef)
                continue;
            if (attriDef.names) {
                values = attris[i].value.split(",");
                len2 = attriDef.names.length;
                for (j = 0; j < len2; ++j) {
                    value = attriDef.type.strToValue(values[j]);
                    value = s.enumTrans(attriDef.enum, value);
                    displayData.attrs[attriDef.names[j]] = value;
                }
            }
            else {
                value = attriDef.type.strToValue(attris[i].value);
                value = s.enumTrans(attriDef.enum, value);
                displayData.attrs[attrName] = value;
            }
        }
        //处理子级        
        len = node.children.length;
        if (len > 0) {
            let obj;
            displayData.childs = [];
            for (i = 0; i < len; ++i) {
                obj = s.parseUI(node.children[i], pkgId);
                if (obj)
                    displayData.childs.push(obj);
            }
        }
        return displayData;
    }
    enumTrans(enumArr, value) {
        let i, len, ind;
        if (enumArr) {
            if (Array.isArray(value)) {
                len = value.length;
                for (i = 0; i < len; ++i) {
                    ind = enumArr.indexOf(value[i]);
                    value[i] = ind;
                }
            }
            else {
                ind = enumArr.indexOf(value);
                value = (ind == -1 ? 0 : ind);
            }
        }
        return value;
    }
}
exports.XMLParser = XMLParser;


/***/ })

/******/ 	});
/************************************************************************/
/******/ 	// The module cache
/******/ 	var __webpack_module_cache__ = {};
/******/ 	
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/ 		// Check if module is in cache
/******/ 		var cachedModule = __webpack_module_cache__[moduleId];
/******/ 		if (cachedModule !== undefined) {
/******/ 			return cachedModule.exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = __webpack_module_cache__[moduleId] = {
/******/ 			// no module.id needed
/******/ 			// no module.loaded needed
/******/ 			exports: {}
/******/ 		};
/******/ 	
/******/ 		// Execute the module function
/******/ 		__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/ 	
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/ 	
/************************************************************************/
/******/ 	/* webpack/runtime/global */
/******/ 	(() => {
/******/ 		__webpack_require__.g = (function() {
/******/ 			if (typeof globalThis === 'object') return globalThis;
/******/ 			try {
/******/ 				return this || new Function('return this')();
/******/ 			} catch (e) {
/******/ 				if (typeof window === 'object') return window;
/******/ 			}
/******/ 		})();
/******/ 	})();
/******/ 	
/************************************************************************/
var __webpack_exports__ = {};
// This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
(() => {
var exports = __webpack_exports__;
/*!*****************!*\
  !*** ./main.ts ***!
  \*****************/

//FYI: https://github.com/Tencent/puerts/blob/master/doc/unity/manual.md
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.onPublish = onPublish;
exports.onDestroy = onDestroy;
var FairyEditor = CS.FairyEditor;
const XMLParser_1 = __webpack_require__(/*! ./xmlUIParse/XMLParser */ "./xmlUIParse/XMLParser.ts");
const Setting_1 = __webpack_require__(/*! ./Setting */ "./Setting.ts");
const Util_1 = __webpack_require__(/*! ./Util */ "./Util.ts");
const App = FairyEditor.App;
const fs = CS.System.IO.File;
const director = CS.System.IO.Directory;
const Path = CS.System.IO.Path;
console.log('welcome GYLite');
// let setting:any = {
//     assetsPath:App.workspaceSettings
// };
App.Alert(JSON.stringify(App.project.settingsPath));
const setting = new Setting_1.Setting;
// let onTestPlay = new CS.FairyGUI.EventCallback1((c) => {
//     console.log("test is play");
// });
// App.On(FairyEditor.EditorEvents.TestStart, onTestPlay);
function getAllXML(path, result = null) {
    if (result == null)
        result = [];
    if (director.Exists(path)) //文件夹
     {
        let arr = director.GetFiles(path);
        let i, len;
        len = arr.Length;
        for (i = 0; i < len; ++i) {
            path = arr.get_Item(i);
            if (director.Exists(path))
                getAllXML(path, result);
            else if (path.indexOf(".xml") == path.length - 4)
                result.push(path);
        }
    }
    else if (path.indexOf(".xml") == path.length - 4)
        result.push(path);
    return result;
}
// // 使用示例：获取上两级目录
// string result = getParentDirectory("Assets/A/B/C/file.txt", 2);
// // 结果: "Assets/A/B"
let menu = App.menu.GetSubMenu("tool");
menu.AddItem("羔羊发布所有包", "GYPublish", (name) => {
    let allPage = App.project.allPackages;
    let i, len, j, len2;
    let files, nameArr;
    let content, fileName, packageName;
    len = allPage.Count;
    for (i = 0; i < len; ++i) {
        let item = allPage.get_Item(i);
        nameArr = item.basePath.split("\\");
        packageName = nameArr[nameArr.length - 1];
        files = getAllXML(item.basePath);
        files.sort((a, b) => {
            if (a.indexOf("\\package.xml") > -1)
                return -1;
            return 1;
        });
        len2 = files.length;
        if (len2 > 0) {
            let pkgId = null;
            let dict = {};
            for (j = 0; j < len2; ++j) {
                content = fs.ReadAllText(files[j]);
                nameArr = files[j].split("\\");
                fileName = nameArr[nameArr.length - 1];
                dict[fileName] = XMLParser_1.XMLParser.getInstance().parse(content, pkgId);
                if (j == 0)
                    pkgId = dict[fileName].attrs.id;
            }
            let assetsPath = Util_1.Util.getParentDirectory(item.basePath, 3);
            assetsPath = Path.Combine(assetsPath, "uiJSON");
            if (!director.Exists(assetsPath))
                director.CreateDirectory(assetsPath);
            assetsPath = Path.Combine(assetsPath, packageName + ".json");
            fs.WriteAllText(assetsPath, JSON.stringify(dict, null, 4));
        }
    }
});
function onDestroy() {
    menu.RemoveItem("GYPublish");
}
function onPublish() {
}
__webpack_require__.g.onPublish = onPublish;
__webpack_require__.g.onDestroy = onDestroy;

})();

/******/ })()
;
//# sourceMappingURL=main.js.map      
      Object.defineProperty(exports, "__esModule", { value: true });
      exports.onPublish = onPublish;
      exports.onDestroy = onDestroy;